import { defineStore } from 'pinia'
import { ref } from 'vue'


//全局新闻信息的pinia仓库
export const NewsStore = defineStore('newsStore', () => {

    //单个新闻
    const newsInfo = ref({})
    const setNewsInfo = (data) => {
        newsInfo.value = data
    }
    const cleanNewsInfo = async() => {
      Object.keys(newsInfo.value).forEach(key => {
        newsInfo.value[key] = null;
      });
    }



    //所有的新闻分类
    const newsCategoryInfo = ref([])
    const setNewsCategoryInfo = (data) => {
        newsCategoryInfo.value = data
    }
    const cleanCategoryInfo = async() => {
      Object.keys(newsCategoryInfo.value).forEach(key => {
        newsCategoryInfo.value[key] = null;
      });
    }
    


  //向外暴露的变量或方法
  return {
    newsCategoryInfo,newsInfo,
    setNewsCategoryInfo,cleanCategoryInfo,setNewsInfo,cleanNewsInfo
  }
})



